package com.adp.interceptor;

import com.adf.config.component.application.report.ReportBean;
import com.adf.system.ReportRequest;
import com.adf.system.intercept.AbsInterceptorDefaultAdapter;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class objFieldEditCondition extends AbsInterceptorDefaultAdapter {
	Map<String, String> map=new HashMap<String, String>();
	
	@SuppressWarnings("unchecked")
	@Override
	public void doStart(ReportRequest rrequest, ReportBean rbean) {
		try {
			String ID=rrequest.getRequest().getParameter("ID");
			
			if (ID!=null) {
				//查询出tbl_s_table_struct表的所有列名
				/*String sql="select column_name from information_schema.columns where table_name='tbl_s_table_struct'";
				Vector<HashtableExtend> vectorcolumns=DBOperator.dataSelect(sql);
				String columns="";  //用来存储列名，用逗号隔开
				if (vectorcolumns!=null&&vectorcolumns.size()>0) {
					for (int i = 0; i < vectorcolumns.size(); i++) {
						columns+=vectorcolumns.get(i).getString("column_name")+",";
					}
				}
				if (!columns.equals("")) {
					columns=columns.substring(0,columns.length()-1);
				}
				
				//根据列名查询出各个列的值
				sql="select "+columns+" from tbl_s_table_struct where ID='"+ID+"'";
				Vector<HashtableExtend> vector=DBOperator.dataSelect(sql);
				String[] str=columns.split(",");
				for (int i = 0; i < str.length; i++) { //将各个列的值存入map集合中
					if (vector.get(0).getString(str[i])!=null&&!vector.get(0).getString(str[i]).equals("")) {
						map.put(str[i],vector.get(0).getString(str[i]));
					}else {
						map.put(str[i],"");
					}
					
				}*/
				map.put("ID", ID);
				Iterator it = map.entrySet().iterator();
				while (it.hasNext()) { //将各个列的值放入session中，已方便xml页面取
					    Map.Entry entry = (Map.Entry) it.next();
					    Object key = entry.getKey();
					    Object value = entry.getValue();
					    rrequest.getRequest().getSession().setAttribute(key.toString(), value.toString());
				 }
			
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("-----这个方法出现错误:"+rrequest.getRequest().getRequestURL()+this.getClass().getName()+"["+Thread.currentThread().getStackTrace()[1].getMethodName()+"]");
		}
		
		super.doStart(rrequest, rbean);
	}
	@SuppressWarnings("unchecked")
	@Override
	public void doEnd(ReportRequest rrequest, ReportBean rbean){
	
	Iterator it = map.entrySet().iterator();
		   while (it.hasNext()) {
			 Map.Entry entry = (Map.Entry) it.next();
		    Object key = entry.getKey();
		    Object value = entry.getValue();
		    rrequest.getRequest().getSession().removeAttribute(key.toString());
		   }
		super.doEnd(rrequest, rbean);
	}
}
